package com.chinatechstar.decis.service.impl;

import com.chinatechstar.base.entity.SysWell;
import com.chinatechstar.base.mapper.SysWellMapper;
import com.chinatechstar.component.commons.utils.DateUtils;
import com.chinatechstar.component.commons.utils.NumericUtils;
import com.chinatechstar.component.commons.utils.ValidateUtils;
import com.chinatechstar.decis.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chinatechstar.decis.service.DesicEvaluationService;
import com.chinatechstar.component.commons.utils.SequenceGenerator;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 业务逻辑实现层
 *
 * @author Rei
 */
@Service
@Transactional
public class DesicEvaluationServiceImpl implements DesicEvaluationService {

    private static final SequenceGenerator SEQUENCE_GENERATOR = new SequenceGenerator();

    @Autowired
    private SysWellMapper sysWellMapper;

    /**
     * 生成综合效果评价结果
     */
    @Override
    public GeneralEffectResultDTO generateGeneralEffect(GeneralEffectWellDTO dto) {
        Date date = dto.getDate();
        Long[] wellIds = dto.getWellIds();
        List<GeneralImplEffectDTO> dtoList = new ArrayList<>();
        GeneralEffectResultDTO result = new GeneralEffectResultDTO();
        result.setEffectiveCount(0);

        // 计算措施有效率
        int total = dtoList.size();
        int effectiveCount = result.getEffectiveCount();
        result.setEffectiveTotal(total);
        if (total > 0) {
            BigDecimal rate = BigDecimal.valueOf(effectiveCount).divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
            result.setEffectiveRate(rate);
        } else {
            result.setEffectiveRate(BigDecimal.ZERO);
        }
        result.setList(dtoList);

        return result;
    }




    /**
     * 生成经济效益评价结果
     */
    @Override
    public EconBenefitResultDTO generateEconBenefit(EconBenefitWellDTO dto) {
        return null;
    }

}
